
#include "main.h"


LINEEQ_DATA g_LineEqData[CAMERA_MAX_NUM][LINEEQ_DATA_MAX_NUM] = {0,};
BYTE g_bLineEqData[CAMERA_MAX_NUM] = {0,};
const BYTE *LINE_NUM = g_bLineEqData;
TOUCH_DATA g_OldTouchs[TOUCH_DATA_MAX_NUM] = {0,};
int g_nOldTouch = 0;


static BYTE _bLineEqRecv = 0;

void Touch_Init(void)
{
	for (u32 i=0; i<TOUCH_DATA_MAX_NUM; i++) {
		g_OldTouchs[i].bId = TOUCH_ID_0 + i;
	}
}
void Touch_Proc(void)
{
	// 0x3 <= ((1<<CAMERA_ID0) && (1<<CAMERA_ID1))
	if (0x3 != (0x3 & _bLineEqRecv)) {
		return;
	}

	touch2_proc();

	_bLineEqRecv = 0;
	memset(g_bLineEqData, 0, sizeof(g_bLineEqData));
}
void Touch_ChangeState(u8 state)
{
	_bLineEqRecv = 0;
	//memset(g_LineEqData, 0, sizeof(g_LineEqData));
	memset(g_bLineEqData, 0, sizeof(g_bLineEqData));
}

void Touch_AddData(u8 dev, u16 dlen, u8 *pdata)
{
	u8 bIdx = dev - DEV_CAMERA1;	// CAMERA_IDn

	if (CAMERA_MAX_NUM > bIdx) {
		int nCount = 0;
		if (dlen) {
			nCount = min((dlen / sizeof(LINEEQ_DATA)),
			(DATA_INPUT_MODE_MOUSE == g_TCD.bInputMode) ? 1 : TOUCH_DATA_MAX_NUM);
		}

		if (LINEEQ_DATA_MAX_NUM >= nCount) {
			if (nCount) {
				memcpy(&g_LineEqData[bIdx][0], pdata, dlen);
			}
			g_bLineEqData[bIdx] = nCount;

			_bLineEqRecv |= (1<<bIdx);
		}
	}
}

